using NHibernate.Cfg;
using NHibernate.Validator.Cfg;
using NHibernate.Validator.Cfg.Loquacious;
using NHibernate.Validator.Engine;
using Environment=NHibernate.Validator.Cfg.Environment;

namespace DMS.BEs.Validations.NHV
{
    public class Config
    {
        private static ValidatorEngine ve;

        public static void Configure(Configuration configuration)
        {
            ValidatorEngine myVE = GetValidatorEngine();

            configuration.Initialize(myVE);
            Environment.SharedEngineProvider = new MyEnvironment(myVE);
        }

        public static ValidatorEngine GetValidatorEngine()
        {
            if (ve != null) return ve;

            FluentConfiguration config = new FluentConfiguration();
            config.SetDefaultValidatorMode(ValidatorMode.UseExternal)
                .Register<CustomerDef, Customer>()
                .IntegrateWithNHibernate.ApplyingDDLConstraints().And.RegisteringListeners();

            ve = new ValidatorEngine();
            ve.Configure(config);

            return ve;
        }

    }
}